extends ScrollContainer

# 用于存储鼠标按下时的起始位置
var start_mouse_position
# 用于存储鼠标按下时的滚动位置
var start_scroll_position

func _on_gui_input(event):
	if event is InputEventMouseButton:
		if event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
			# 鼠标左键按下，记录起始位置和滚动位置
			start_mouse_position = event.position
			start_scroll_position = Vector2(scroll_horizontal, scroll_vertical)
	elif event is InputEventMouseMotion:
		if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
			# 鼠标左键按住并移动，计算偏移量并更新滚动位置
			var delta = event.position - start_mouse_position
			scroll_horizontal = start_scroll_position.x - delta.x
			scroll_vertical = start_scroll_position.y - delta.y
			# 确保滚动位置不超出范围
			scroll_vertical = clamp(scroll_vertical, 0, get_v_scroll_bar().max_value)

func update(desc:String):
	$"VBoxContainer/技能1".visible = false
	$"VBoxContainer/技能2".visible = false
	$"VBoxContainer/技能3".visible = false
	$"VBoxContainer/技能4".visible = false
	var parts = desc.split("_")
	if parts.size() < 1 || parts[0] == "":
		return
	$"VBoxContainer/技能1".visible = true
	$"VBoxContainer/技能1".setText(parts[0])
	if parts.size() < 2:
		return
	$"VBoxContainer/技能2".visible = true
	$"VBoxContainer/技能2".setText(parts[1])
	if parts.size() < 3:
		return
	$"VBoxContainer/技能3".visible = true
	$"VBoxContainer/技能3".setText(parts[2])
	if parts.size() < 4:
		return
	$"VBoxContainer/技能4".visible = true
	$"VBoxContainer/技能4".setText(parts[3])
